﻿using System.Drawing.Drawing2D;
using System.Collections.Generic;
using System.Drawing;

namespace PTCapture.Support.Angles
{
    /// <summary>
    /// Drawer for user angle
    /// </summary>
    public class UserAngleManager
    {
        #region Fields

        /// <summary>
        /// Angle we are currently drawing
        /// </summary>
        public UserAngle inProgressAngle = null;

        /// <summary>
        /// List of completed angles
        /// </summary>
        public List<UserAngle> angles = new List<UserAngle>();

        #endregion

        #region Support

        /// <summary>
        /// Clicking adds a point and completes when 3 points added.
        /// </summary>
        /// <param name="mousePoint"></param>
        /// <param name="color"></param>
        /// <param name="acute"></param>
        /// <returns></returns>
        public UserAngle Click(Point mousePoint, Color color, bool acute)
        {
            if (inProgressAngle == null)
            {
                inProgressAngle = new UserAngle(mousePoint, null, null, color, acute);
            }
            else if (inProgressAngle.B == null)
            {
                inProgressAngle.B = mousePoint;
            }
            else
            {
                inProgressAngle.C = mousePoint;

                angles.Add(new UserAngle(inProgressAngle));
                inProgressAngle = null;

                return angles[angles.Count - 1];
            }

            return null;
        }

        #endregion
    }
}
